﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApSelectedCableEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

public class CApSelectedCableEnabler : ITxCommandEnabler
{
  public bool Enable
  {
    get
    {
      if (!this.ShouldEnable() || this.IsSimulationRunning)
        return false;
      return TxApplication.ActiveDocument.CurrentStudy != null || TxCollisionRoot.op_Inequality(TxApplication.ActiveDocument.CollisionRoot, (ITxObject) null);
    }
  }

  private bool ShouldEnable()
  {
    bool flag = false;
    if (TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded())
    {
      foreach (ITxObject allItem in (Collection<ITxObject>) TxApplication.ActiveSelection.GetAllItems())
      {
        if (this.IsCableObject(allItem))
        {
          flag = true;
        }
        else
        {
          flag = false;
          break;
        }
      }
    }
    return flag;
  }

  private bool IsCableObject(ITxObject selectedObj) => selectedObj is ITxCable;

  private bool IsSimulationRunning
  {
    get => TxApplication.ActiveDocument.SimulationPlayer.IsSimulationRunning();
  }
}
